package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Account;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAccountService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
//20220406分支测试2
@Controller
@RequestMapping("account")
public class AccountController {

    @Autowired
    private IAccountService accountService;

    @RequestMapping("list")
    @ResponseBody
    public List<Account> list() {
        return accountService.selectAll();
    }

    @RequestMapping("view")
    @RequiresPermissions(value = {"account:view","账户界面"},logical = Logical.OR)
    public String query(QueryObject qo) {
        return "account";
    }

    @RequestMapping("saveOrUpdate")
    @RequiresPermissions(value = {"account:saveOrUpdate","账户新增/更新"},logical = Logical.OR)
    @ResponseBody
    public Object saveOrUpdate(Account account) {
        JSONResult result = new JSONResult();
        try {
            accountService.saveOrUpdate(account);
        } catch (Exception e) {
            result.remark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult account(QueryObject qo) {
        return accountService.query(qo);
    }
}
